/*******************************************************************************
 * BIP ADMIN VIEW
 * 
 * Copyright:
 * 
 * License:
 * 
 * Authors: SALMON Charles
 * 
 ******************************************************************************/

/*******************************************************************************
 * 
 ******************************************************************************/

/**
 * The GUI definition of the bip admin view
 */
qx.Class.define("bip.AdminView", {
	extend : qx.ui.container.Composite,
	
	type: "singleton",
	
	/*
	 * ****************************************************************************
	 * CONSTRUCTOR
	 * ****************************************************************************
	 */

	construct : function() {
		this.base(arguments);

		// Configure layout
		var layout = new qx.ui.layout.VBox;
		layout.setSeparator("separator-vertical");
		this.setLayout(layout);

		// Header
		this.add(this.__createHeader());

	  // Commands & Menu Bar
		this.__makeCommands();
		this.__menuBar = this.__makeToolBar();
		this.add(this.__menuBar);
		
		// Desktop
		this.__desktop = new qx.ui.window.Desktop();
		this.add(this.__desktop,{flex:1});
		
	
	},

	/*
	 * ****************************************************************************
	 * PROPERTIES
	 * ****************************************************************************
	 */

	properties : {

	},

	/*
	 * ****************************************************************************
	 * MEMBERS
	 * ****************************************************************************
	 */

	members : {
		__winNewTopic:null,
		__winSearchTopic:null,
		__winFillSurvey:null,
		__winManageTopics:null,
		__desktop:null,
		__topicService:null,
		__questionService:null,
		
		getWinNewTopic: function() {
			if (! this.__winNewTopic) {
				this.__winNewTopic = new bip.ui.topics.WinNewTopicForm();
				this.__desktop.add(this.__winNewTopic);
			}
			return this.__winNewTopic;
		},
		
		getTopicService: function() {
			if (! this.__topicService) {
				this.__topicService = new bip.services.TopicService();
			}
			return this.__topicService;
		},
		
		getQuestionService: function() {
			if (! this.__questionService) {
				this.__questionService = new bip.services.QuestionService();
			}
			return this.__questionService;
		},
		
		getDesktop: function() {
			return this.__desktop;
		},
		
		// ------------------------------------------------------------------------
		// CONSTRUCTOR HELPERS
		// ------------------------------------------------------------------------
		/**
		 * Creates the application header.
		 */
		__createHeader : function() {
			var layout = new qx.ui.layout.HBox();
			var header = new qx.ui.container.Composite(layout);
			header.setAppearance("app-header");

			var title = new qx.ui.basic.Label("BIP [ADMIN]");
			var user = bip.rpc.RpcManager.getInstance().getUserName();
			var userNameLabel = new qx.ui.basic.Label("user:" + user);

			header.add(title);
			header.add(new qx.ui.core.Spacer, {
				flex : 1
			});
			header.add(userNameLabel);

			return header;
		},
		
		__makeCommands : function() {
			/*this._cmdObjectSummary = new qx.ui.core.Command("Ctrl+O");
			this._cmdObjectSummary.addListener("execute",
					this.__getObjectSummary, this);

			this._cmdRunSample = new qx.ui.core.Command("F5");
			this._cmdRunSample.addListener("execute", this.runSample, this);

			this._cmdPrevSample = new qx.ui.core.Command("Ctrl+Left");
			this._cmdPrevSample.addListener("execute", this.playPrev, this);

			this._cmdNextSample = new qx.ui.core.Command("Ctrl+Right");
			this._cmdNextSample.addListener("execute", this.playNext, this);

			this._cmdSampleInOwnWindow = new qx.ui.core.Command("Ctrl+N");
			this._cmdSampleInOwnWindow.addListener("execute",
					this.__openWindow, this);

			this._cmdDisposeSample = new qx.ui.core.Command("Ctrl+D");
			this._cmdDisposeSample.addListener("execute", this.__disposeSample,
					this);

			this._cmdNamespacePollution = new qx.ui.core.Command("Ctrl+P");
			this._cmdNamespacePollution.addListener("execute",
					this.__showPollution, this);*/
		},
		
		__makeToolBar : function() {
			var bar = new qx.ui.toolbar.ToolBar();
			
			// TOPICS
			var topicsButton = new qx.ui.toolbar.Button(this.tr("Topics"),"bip/icon/topics.png");
			topicsButton.setIconPosition("top");
			topicsButton.setToolTipText("Manage topics");
			topicsButton.addListener("execute",function() {
				if (! this.__winManageTopics) {
					this.__winManageTopics = new bip.ui.topics.WinManageTopics();
					this.__desktop.add(this.__winManageTopics);
				} 
				this.__winManageTopics.show();
			},this);
			bar.add(topicsButton);

//		  // TOPIC MENU
//			// -----------------------------------------------------
//			this.__topicPart = new qx.ui.toolbar.Part;
//			bar.add(this.__topicPart);
//
//			this.__topicMenu = new qx.ui.menu.Menu;
//
//			// TOPICS
//			var t1 = new qx.ui.menu.Button("New topic");
//			t1.addListener("execute",function() {
//				if (! this.__winNewTopic) {
//					this.__winNewTopic = new bip.ui.topics.WinNewTopicForm();
//					this.__desktop.add(this.__winNewTopic);
//				} 
//				this.__winNewTopic.show();
//				
//			},this);
//			this.__topicMenu.add(t1);
//			
//			var t12 = new qx.ui.menu.Button("Find topic");
//			t12.addListener("execute",function() {
//				if (! this.__winSearchTopic) {
//					this.__winSearchTopic = new bip.ui.topics.WinSearchTopics();
//					this.__desktop.add(this.__winSearchTopic);
//				} 
//				this.__winSearchTopic.show();
//				
//			},this);
//			this.__topicMenu.add(t12);
//			
//			var t13 = new qx.ui.menu.Button("Manage topics");
//			t13.addListener("execute",function() {
//				if (! this.__winManageTopics) {
//					this.__winManageTopics = new bip.ui.topics.WinManageTopics();
//					this.__desktop.add(this.__winManageTopics);
//				} 
//				this.__winManageTopics.show();
//				
//			},this);
//			this.__topicMenu.add(t13);
//			
//			this.__topicMenu.add(new qx.ui.menu.Separator());
//			
//			// QUESTIONS
//			var t2 = new qx.ui.menu.Button("New question");
//			t2.addListener("execute",function() {
//				if (! this.__winNewQuestion) {
//					this.__winNewQuestion = new bip.ui.questions.WinNewQuestionForm();
//					this.__desktop.add(this.__winNewQuestion);
//				} 
//				this.__winNewQuestion.show();
//				
//			},this);
//			this.__topicMenu.add(t2);
//			
//			this.__topicMenu.add(new qx.ui.menu.Separator());
//			
//			// SURVEY
//			var t3 = new qx.ui.menu.Button("Fill survey");
//			t3.addListener("execute",function() {
//				if (! this.__winFillSurvey) {
//					this.__winFillSurvey = new bip.ui.survey.WinFillSurvey();
//					this.__desktop.add(this.__winFillSurvey);
//				} 
//				this.__winFillSurvey.show();
//				
//			},this);
//			this.__topicMenu.add(t3);
//
//
//			var topicButton = new qx.ui.toolbar.MenuButton(this.tr("Topics"),
//					"icon/48/apps/internet-messenger.png", this.__topicMenu);
//			topicButton.setIconPosition("top");
//			topicButton.setToolTipText("Manage topics");
//			this.__topicPart.add(topicButton);
			
			// THEME MENU
			// -----------------------------------------------------

			/*var menuPart = new qx.ui.toolbar.Part;
			this.__themePart = menuPart;
			bar.add(menuPart);

			var themeMenu = new qx.ui.menu.Menu;

			this.__themeMenu = themeMenu;

			var t1 = new qx.ui.menu.RadioButton("Modern Theme");
			var t2 = new qx.ui.menu.RadioButton("Classic Theme");

			t1.setUserData("value", "qx.theme.Modern");
			t1.setValue(true);
			t2.setUserData("value", "qx.theme.Classic");

			var group = new qx.ui.form.RadioGroup(t1, t2);
			group.addListener("changeSelection", this.__onChangeTheme, this);

			themeMenu.add(t1);
			themeMenu.add(t2);

			var themeButton = new qx.ui.toolbar.MenuButton(this.tr("Theme"),
					"icon/22/apps/utilities-color-chooser.png", themeMenu);
			themeButton.setToolTipText("Choose theme");
			menuPart.add(themeButton);*/

			// DONE
			// -----------------------------------------------------
			return bar;
			
		}

	},

	/*
	 * ****************************************************************************
	 * DESTRUCTOR
	 * ****************************************************************************
	 */

	destruct : function() {
		this._disposeObjects("__winNewTopic","__winNewQuestion","__winSearchTopic","__winManageTopics","__winFillSurvey",
				"__topicService","__questionService");
	}
});
